<html lang="en">
<head>
    <base href="${title}/">
    <meta charset="UTF-8">
    <link rel="stylesheet" href="/ant-design/antd.min.css">

</head>

<style>
    .disable {
        pointer-events: none;
    }
</style>

<body>
<div>
    <form class="ant-form ant-form-horizontal" style="margin-top: 20px">
        <div class="ant-row ant-form-item">
            <div class="ant-col ant-col-sm-4 ant-form-item-label">
                <label for="phoneCode" title="验证码" class="ant-form-item-required">验证码
                </label>
            </div>
            <div class="ant-col ant-col-sm-20 ant-form-item-control-wrapper">
                <div class="ant-form-item-control">
                    <span class="ant-form-item-children">
                        <span class="ant-input-group-wrapper" style="width: 300px;">
                            <span class="ant-input-wrapper ant-input-group">
                                <input type="text"
                                       id="phoneCode"
                                       class="ant-input ng-pristine ng-valid ant-input-lg ng-star-inserted ng-touched">
                    <span class="ant-input-group-addon">
                        <div class="cursor ant-spin-nested-loading">
                            <div id="codeBtn" style="cursor: pointer" class="ant-spin-container" onclick="getCode()"> 获取验证码
                            </div>
                        </div>
                    </span>
                            </span>
                        </span>
                    </span>
                </div>
            </div>
        </div>

        <div class="ant-row ant-form-item">
            <div class="ant-col ant-col-sm-4 ant-form-item-label">
                <label for="password" title="请输入新密码" class="ant-form-item-required">新密码</label>
            </div>
            <div class="ant-col ant-col-sm-20 ant-form-item-control-wrapper" style="width: 300px;">
                <div class="ant-form-item-control has-success">
                    <span class="ant-form-item-children">
                        <input type="password"
                               id="password"
                               class="ant-input ng-pristine ng-valid ant-input-lg ng-star-inserted ng-touched">
                    </span>
                </div>
            </div>
        </div>
        <div class="ant-row ant-form-item">
            <div class="ant-col ant-col-sm-4 ant-form-item-label">
                <label for="checkPassword" title="请输入新密码" class="ant-form-item-required">确认密码</label>
            </div>
            <div class="ant-col ant-col-sm-20 ant-form-item-control-wrapper" style="width: 300px;">
                <div class="ant-form-item-control has-success">
                    <span class="ant-form-item-children">
                        <input type="password"
                               id="checkPassword"
                               class="ant-input ng-pristine ng-valid ant-input-lg ng-star-inserted ng-touched">
                    </span>
                </div>
            </div>
        </div>
    </form>


    <div class="ant-modal-footer ng-star-inserted">
        <button class="ant-btn ng-star-inserted ant-btn-default" onclick="cancel()">
            <span> 取消 </span>
        </button>
        <button class="ant-btn ng-star-inserted ant-btn-primary" onclick="update()">
            <span> 修改 </span>
        </button>
    </div>

</div>
</body>
<script src="/jquery-3.5.1.min.js"></script>
<script src="/url.js"></script>
<script>
    let s = 60;
    function getCode() {
        if (s != 60) {
            return;
        }
        let url = requestUrl + "/erupt-api/adminCode/get";
        $.ajax({
            type: "POST",
            url: url,
            headers: {
                token: parent.getAppToken().token
            },
            data: {},
            datatype: "json",
            success: function (result) {
                console.log(result)
                if (result.code == 1) {
                    let timer = setInterval(function () {
                        s--;
                        let name = s + "s后获取";
                        console.log(name)
                        document.getElementById('codeBtn').innerHTML = name
                        if (s < 1) {
                            s = 60;
                            document.getElementById('codeBtn').innerHTML = '获取验证码'
                            clearInterval(timer);
                        }
                    }, 1000);
                } else {
                    if (result.message != undefined) {
                        alert(result.message)
                    } else if (result.msg != undefined) {
                        alert(result.msg)
                    }
                }
            }
        });
    }

    function cancel() {
        parent.document.querySelector(".ant-modal-close-x").click()
    }

    function update() {
        let phoneCode = $("#phoneCode").val();
        let password = $("#password").val();
        let checkPassword = $("#checkPassword").val();

        if (phoneCode == '') {
            alert('验证码不能为空')
            return;
        }
        if (password == '' || checkPassword == '') {
            alert('密码不能为空')
            return;
        }
        if (password != checkPassword) {
            alert('两次密码不一致')
            return;
        }
        let url = requestUrl + "/erupt-api/opPassword/update";
        $.ajax({
            type: "POST",
            url: url,
            headers: {
                token: parent.getAppToken().token
            },
            data: {
                code: phoneCode,
                password: password,
            },
            datatype: "json",
            success: function (result) {
                console.log(result)
                if (result.code == 1) {
                    parent.document.querySelector(".ant-modal-close-x").click()
                } else {
                    if (result.message != undefined) {
                        alert(result.message)
                    } else if (result.msg != undefined) {
                        alert(result.msg)
                    }
                }
            }
        });
    }

</script>

</html>